package org.pageley.games.connected.domain.environment;

import java.util.Collection;
import java.util.HashSet;

import org.pageley.games.domain.Direction;
import org.pageley.games.domain.Location;

public class ForkedRoad extends AbstractRoad {

	public ForkedRoad(Location location, Direction start, boolean right, boolean inbound) {
		super(location, 3.0, 
				directionsFrom(start, right, inbound), 
				directionsTo(start, right, inbound));
	}

	private static Collection<Direction> directionsFrom(Direction start,
			boolean right, boolean inbound) {
		Collection<Direction> directions = new HashSet<Direction>();
		directions.add(start);
		if(inbound) {
			directions.add(right ? start.turn(-2) : start.turn(2));
		}
		return directions;
	}

	private static Collection<Direction> directionsTo(Direction start,
			boolean right, boolean inbound) {
		Collection<Direction> directions = new HashSet<Direction>();
		directions.add(start.oppositeDirection());
		if(!inbound) {
			directions.add(right ? start.turn(-2) : start.turn(2));
		}
		return directions;
	}

}
